FROM isrc.iscas.ac.cn/learningeulixos/debian:sid-slim as builder

ENV DEBIAN_FRONTEND=noninteractive

RUN cat <<'EOF' > /etc/apt/sources.list.d/debian.sources
Types: deb
URIs: http://mirror.iscas.ac.cn/debian
Suites: sid
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF

RUN apt update && \
    apt install -y node-corepack nodejs curl build-essential chromium

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y 
ENV PATH="/root/.cargo/bin:${PATH}"

RUN corepack enable pnpm

COPY ./ /src/
WORKDIR /src/

RUN cargo install mdbook mdbook-pdf && \ 
    mdbook --version && \
    mdbook build /src/mdbook/eulixos-camp-book-stage0-docs && \
    mdbook build /src/mdbook/eulixos-camp-book-stage1-docs && \
    mdbook build /src/mdbook/eulixos-camp-book-stage2-docs

RUN pnpm install

RUN pnpm run build

RUN mkdir -p /usr/share/nginx/html/eulixos-camp-book-stage0-docs \
    /usr/share/nginx/html/eulixos-camp-book-stage1-docs \
    /usr/share/nginx/html/eulixos-camp-book-stage2-docs 

FROM isrc.iscas.ac.cn/learningeulixos/nginx:latest

COPY --from=builder /src/public /usr/share/nginx/html
COPY --from=builder /src/mdbook/eulixos-camp-book-stage0-docs/book/html /usr/share/nginx/html/eulixos-camp-book-stage0-docs 
COPY --from=builder /src/mdbook/eulixos-camp-book-stage1-docs/book /usr/share/nginx/html/eulixos-camp-book-stage1-docs 
COPY --from=builder /src/mdbook/eulixos-camp-book-stage2-docs/book /usr/share/nginx/html/eulixos-camp-book-stage2-docs 

EXPOSE 80
